<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace plugins\comment;//Demo插件英文名，改成你的插件英文就行了
use cmf\lib\Plugin;
use plugins\comment\model\CommentModel;

//Demo插件英文名，改成你的插件英文就行了
class CommentPlugin extends Plugin
{

    public $info = [
        'name'        => 'Comment',//Demo插件英文名，改成你的插件英文就行了
        'title'       => '评论插件',
        'description' => '评论插件',
        'status'      => 1,
        'author'      => 'ThinkCMF',
        'version'     => '1.0.0',
        'demo_url'    => 'http://demo.thinkcmf.com',
        'author_url'  => 'http://www.thinkcmf.com'
    ];

    public $hasAdmin = 1;//插件是否有后台管理界面

    // 插件安装
    public function install()
    {
        return true;//安装成功返回true，失败false
    }

    // 插件卸载
    public function uninstall()
    {
        return true;//卸载成功返回true，失败false
    }

    //实现的comment钩子方法
    public function comment($param)
    {
        $commentModel = new CommentModel();
        $comments     = $commentModel
            ->where([
                "table_name" => $param['table_name'],
                "object_id"  => $param['object_id'],
                "status"     => 1,
            ])
            ->order('create_time DESC')
            ->paginate(10, false, ['var_page' => 'comment_page']);
        $config       = $this->getConfig();
        $this->assign($config);
        $this->assign('param', $param);
        $this->assign('user', cmf_get_current_user());
        $this->assign('comments', $comments);
        $this->assign('page', $comments->render());
        return $this->fetch('widget');
    }

}